// ------ 定义一个对象 -----------
var object_name = { 
    key1: "value1", // 标量
    key3: function(text: string) {
        // 函数
        console.log("打印对象里面的函数:" + text)
    }, 
    key4:["content1", "content2"], //集合
    defineFun:Function()
}
object_name.defineFun = function(txt: string){
    console.log("打印对象外面的函数:" + txt)
}

// ---- 将对象声明成一个类型 -------
type User = {
    name:string 
    age?:number // 可选属性，可以不赋值
    addr:string
    study(clazz:string, room:string):void
}
var user:User = {
    name:"zhangsan",
    // age:18,
    addr:"wuhan",
    study(clazz:string, room:string):void{
        console.log("年级：" + clazz + " 教室：" + room)
    }
}

// --------- 属性名索引类型 ---------
// 属性名可以动态定义
 type DynamicProperty = {
    // 属性名是string，属性值也是string
    [property: string|number]: string|number
 }

 var demo: DynamicProperty = {
    key1: "value1",
    key2: "value2",
    3 : "333",
    sss:555
 }

 console.log(object_name)
object_name.key3("大吉大利晚上吃鸡")
object_name.defineFun("外面定义的函数")

console.log(user)
console.log(user.name)
user.study("三年级", "102室")

 console.log(demo.key1)
 console.log(demo.sss)

